package ink.lovejinhu.swardToOffer;

import java.util.Arrays;

/**
 * @Author: jin
 * @ClassName: Person
 * @Date: 2021/8/22 20:41
 * @Version: V1.0
 **/
public class Offer_061 {
    /**
     * 扑克牌中的顺子
     * 大小王是癞子
     *
     * @param nums
     * @return
     */
    public boolean isStraight(int[] nums) {  //就两个王

        Arrays.sort(nums);
        int laizi = 0;
        int distance = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] == 0) {
                laizi++;
                continue;
            }
            if (nums[i] == nums[i + 1]) {
                return false;
            }
            if (nums[i] + 1 != nums[i + 1]) {
                distance += nums[i + 1] - nums[i] - 1;
            }
        }
        System.out.println(laizi);
        return distance <= laizi;
    }

    public static void main(String[] args) {
        int[] test = {0, 0, 1, 2, 5};
        Offer_061 offer_061 = new Offer_061();
        boolean straight = offer_061.isStraight(test);
        System.out.println(straight);
    }

}
